<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="">
        <el-breadcrumb-item>
          <div class="div1">订单管理</div>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <div v-if="jage == 1" class="div2">客户被退货</div>
          <div v-if="jage == 0" class="div2">客户拒收</div>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 面包屑导航 -->
    <div class="orderInfo">
      <div class="title">
        <span>订单信息</span>
      </div>
      <div class="content" v-if="!is_null(content.orderUser)">
        <div class="contentTemp">
          <div class="fontTemp">
            <!-- <span class="span">原单编号: {{content.orderUser.orderId}}</span> -->
            <span class="span">订单编号: {{ content.orderUser.orderIdStr }}</span>
            <span class="span"
              >订单状态: {{ content.orderUser.orderType }}</span
            >
            <div class="span" style="display:inline-block;">
              <span class="span1">时 间</span>
              <span>:{{ content.orderUser.createdTime }}</span>
            </div>
            <div class="span" style="display:inline-block;">
              <span class="span1">客 服:</span>
              <span>{{ content.orderUser.employeeName }}</span>
            </div>
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span"
              >客户信息: {{ content.orderUser.customerUserName }}
              {{ content.orderUser.customerUserPhone }}
              {{ content.orderUser.detailedAddress }}</span
            >
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span"
              >收货信息: {{ content.orderUser.addressName }}
              {{ content.orderUser.addressPhone }}
              {{ content.orderUser.address }}</span
            >
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span">物流备注: 无</span>
          </div>
        </div>

        <div class="contentTemp" v-if="jage == 0">
          <div class="fontTemp">
            <span class="span"
              >包裹单号:
              {{ content.orderUser.logisticsOrder.logisticsCompany }}
              {{ content.orderUser.logisticsOrder.parcelNumber }}</span
            >
          </div>
        </div>

        <div class="contentTemp" v-if="jage == 1">
          <div class="fontTemp">
            <p><span>*</span>物流公司:</p>
            <div>
              <el-select
                v-model="logisticsCompany"
                placeholder="快递公司"
                filterable
                clearable
              >
                <el-option
                  v-for="itemsS in companys"
                  :key="itemsS.dictName"
                  :label="itemsS.dictName"
                  :value="itemsS.dictName"
                ></el-option>
              </el-select>
            </div>
            <div>
              <el-input
                type="text"
                placeholder="请输入包裹物流单号"
                v-model="logistCode"
              ></el-input>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="goodDetail">
      <div class="title">商品详情</div>
      <div class="content">
        <div class="title" style="border:0;">商品</div>
        <el-table
          :data="content.orderCommodityList"
          :header-cell-style="{ color: '#333', textAlign: 'center' }"
          style="width: 100%"
        >
          <el-table-column prop="brandName" label="品牌"> </el-table-column>
          <el-table-column width="200" prop="name" label="商品名称">
          </el-table-column>
          <el-table-column prop="number" label="原单数量"> </el-table-column>
          <!-- 物流操作 -->
          <el-table-column label="仓库收货" width="200">
            <template slot-scope="scope">
              <div class="optain">
                <div class="inputDeal">
                  <span>正常</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.receivedNum"
                      :value="scope.row.receivedNum"
                      @change="changCountRecived(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.receivedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeRecived(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeRecived(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>破损</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.damagedNum"
                      :value="scope.row.damagedNum"
                      @change="changeCountDamage(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.damagedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeDamage(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeDamage(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>漏件</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.missingNum"
                      :value="scope.row.missingNum"
                      @change="changeCountMissing(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.missingNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeMissing(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeMissing(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <!-- 物流操作 -->
          <el-table-column label="单价">
            <template slot-scope="scope"> ￥{{ scope.row.price }} </template>
          </el-table-column>
          <el-table-column prop="specificationName" label="规格">
          </el-table-column>

          <el-table-column label="拒收小计" v-if="jage == 0">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>

          <el-table-column label="退货小计" v-if="jage == 1">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>
        </el-table>
        <div class="title" style="border:0;">赠品</div>
        <el-table
          :data="content.orderComplimentaryList"
          :header-cell-style="{ color: '#333', textAlign: 'center' }"
          style="width: 100%"
        >
          <el-table-column prop="brandName" label="品牌"> </el-table-column>
          <el-table-column
            width="200"
            prop="complimentaryName"
            label="商品名称"
          >
          </el-table-column>
          <el-table-column prop="number" label="原单数量"> </el-table-column>
          <!-- <el-table-column label="仓库收货">
						<template slot-scope="scope">
							<div style="white-space: nowrap;">
								已收：{{ scope.row.warehouse.received }}件
							</div>
							<div style="white-space: nowrap;">
								破损：{{ scope.row.warehouse.damaged }}件
							</div>
							<div style="white-space: nowrap;">
								漏件：{{ scope.row.warehouse.missingPart }}件
							</div>
						</template>
					</el-table-column> -->

          <!-- 物流操作 -->
          <el-table-column label="仓库收货" width="200">
            <template slot-scope="scope">
              <div class="optain">
                <div class="inputDeal">
                  <span>正常</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.receivedNum"
                      :value="scope.row.receivedNum"
                      @change="changCountRecivedZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.receivedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeRecivedZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeRecivedZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>破损</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.damagedNum"
                      :value="scope.row.damagedNum"
                      @change="changeCountDamageZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.damagedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeDamageZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeDamageZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>漏件</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.missingNum"
                      :value="scope.row.missingNum"
                      @change="changeCountMissingZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.missingNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeMissingZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeMissingZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <!-- 物流操作 -->

          <el-table-column label="单价">
            <template slot-scope="scope"> ￥{{ scope.row.price }} </template>
          </el-table-column>
          <el-table-column prop="specificationName" label="规格">
          </el-table-column>

          <el-table-column label="拒收小计" v-if="jage == 0">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>

          <el-table-column label="退回小计" v-if="jage == 1">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>
        </el-table>
        <div class="totalAll" v-if="!is_null(content.orderUser)">
          <span>原单总计：共{{ content.orderUser.pieceNumber }}件</span>
          <span>运费：{{ content.orderUser.charge }}元</span>
          <span>赠品总价 ￥ {{ content.orderUser.giftTotal }}</span>
          <span>商品总价 ￥ {{ content.orderUser.goodsTotal }}</span>
          <span>应收金额 ￥ {{ content.orderUser.total }}</span>
          <span>已收金额 ￥ {{ content.orderUser.receivedMoney }}</span>
          <span>待收金额 ￥ {{ content.orderUser.awaitIncomeMoney }}</span>
        </div>
        <div class="totalAll" v-if="!is_null(content.orderUser)">
          <span>仓库收货总计</span>
          <span>正常 {{ receivedTogether }} 件</span>
          <span>破损 {{ damagedTogether }} 件</span>
          <span>漏件 {{ missingTogether }} 件</span>
          <span>已收货总价 ￥ {{ content.orderUser.total }}</span>
        </div>
        <!-- 	"总 计 : 已收" + this.receivedTogether + "件, 破损 : " + this.damagedTogether + "件, 漏件 : " + this.missingTogether +
					" 件", -->
        <!-- 		<div class="total" v-if='!is_null(content.orderUser)'>
					<span>已收金额 ￥ {{content.orderUser.receivedMoney}}</span>
				</div>
				<div class="total" v-if='!is_null(content.orderUser)'>
					<span>应退 ￥ {{content.orderUser.receivedMoney}}</span>
				</div> -->
      </div>
    </div>
    <div class="remark">
      <div class="title">备注</div>
      <el-input
        type="textarea"
        :rows="2"
        placeholder="请输入内容"
        v-model="textarea"
      >
      </el-input>
    </div>
    <div style="height:70px;"></div>
    <div class="submit" v-if="jage == 0">
      <el-button
        type="primary"
        size="mini"
        style="width:100px;"
        @click="submitEvent()"
        >提交</el-button
      >
    </div>

    <div class="submit" v-if="jage == 1">
      <el-button
        type="primary"
        size="mini"
        style="width:100px;"
        @click="submitEvent()"
        >提交被退货</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      orderId: "",
      content: "",
      textarea: "",
      tableData: [],
      backNumTotal: 0,
      receivedTogether: 0,
      damagedTogether: 0,
      missingTogether: 0,
      packages: 0, //总(商品+赠品)件数
      jage: 0,
      logisticsCompany: "",
      logistCode: "",
      companys: [],
      together: 0,
      orginNumber: 0,
    };
  },
  created() {
    this.orderId = this.$route.query.orderId;
    this.jage = this.$route.query.jage; //1为 被退货 0拒收
    if (this.jage == 1) {
      this.logisticsExpress();
    }
    this.detailAxios();
  },
  methods: {
    /**
     * 详情
     * **/
    detailAxios() {
      this.axios
        .get("/order/order/user/detail/" + this.orderId + "?type=" + "")
        .then((res) => {
          // console.log(res);
          if (res.code == 0) {
            // 插入商品,赠品仓库默认的数据
            let goodsTotal = 0;
            let numbergoods = 0;
            for (let i = 0; i < res.data.orderCommodityList.length; i++) {
              res.data.orderCommodityList[i].receivedNum = 0; //已收
              res.data.orderCommodityList[i].damagedNum = 0; //破损
              res.data.orderCommodityList[i].missingNum = 0; //漏件
              goodsTotal += parseInt(res.data.orderCommodityList[i].total);
              numbergoods += res.data.orderCommodityList[i].number;
            }
            res.data.orderUser.goodsTotal = goodsTotal;

            let giftTotal = 0;
            let giftNumber = 0;
            if (!this.is_null(res.data.orderComplimentaryList)) {
              for (let i = 0; i < res.data.orderComplimentaryList.length; i++) {
                res.data.orderComplimentaryList[i].receivedNum = 0; //已收
                res.data.orderComplimentaryList[i].damagedNum = 0; //破损
                res.data.orderComplimentaryList[i].missingNum = 0; //漏件
                giftTotal += Number(res.data.orderComplimentaryList[i].total);
                giftNumber += res.data.orderComplimentaryList[i].number;
              }
            }
            res.data.orderUser.giftTotal = giftTotal;
            this.packages = numbergoods + giftNumber;
            this.content = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
    },
    /**
     * 详情
     * **/
    /**
     * 查询物流快递公司
     **/
    logisticsExpress() {
      this.axios
        .get("/sys/v1/common/by/group?groupId=courier_company", {
          headers: {
            isLoading: false,
          },
        })
        .then((res) => {
          // console.log(res);
          if (res.code == 0) {
            this.companys = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
    },
    /**
     * 查询物流快递公司
     **/
    /**
     * 商品已收 破损 漏件 数量操作修改
     **/
    changCountRecived(row, index) {
      if (
        null == row.receivedNum ||
        row.receivedNum == "" ||
        (row.receivedNum != "number" && isNaN(row.receivedNum))
      ) {
        row.receivedNum = 0;
      } else if (row.receivedNum <= 0) {
        row.receivedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.receivedNum > row.number) {
        row.receivedNum = 0;
        this.$message.warning("已收数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) +
          parseInt(row.missingNum) +
          parseInt(row.damagedNum) >
        row.number
      ) {
        row.receivedNum = 0;
        this.$message.warning("已收 + 破损 +漏件 不能大于原单数量");
      }

      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeRecived(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.receivedNum >= row.number) {
          this.$message.warning("已收数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("已收+破损+漏件 不能大于原单数量");
        } else {
          row.receivedNum++;
        }
      } else {
        row.receivedNum--;
        row.receivedNum > 0 ? row.receivedNum : (row.receivedNum = 0);
      }
      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    // 破损
    changeCountDamage(row, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (
        null == row.damagedNum ||
        row.damagedNum == "" ||
        (row.damagedNum != "number" && isNaN(row.damagedNum))
      ) {
        row.damagedNum = 0;
      } else if (row.damagedNum <= 0) {
        row.damagedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.damagedNum >= row.number) {
        row.damagedNum = 0;
        this.$message.warning("破损数不能大于原单数量");
      } else if (addNum > row.number) {
        row.damagedNum = 0;
        this.$message.warning("正常 + 破损 +漏件 不能大于原单数量");
      }
      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeDamage(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.damagedNum >= row.number) {
          row.damagedNum = 0;
          this.$message.warning("破损数不能大于原单数量");
        } else if (addNum >= row.number) {
          row.damagedNum = 0;
          this.$message.warning("正常+破损+漏件 不能大于原单数量");
        } else {
          row.damagedNum++;
        }
      } else {
        row.damagedNum--;
        row.damagedNum > 0 ? row.damagedNum : (row.damagedNum = 0);
      }
      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    // 漏件
    changeCountMissing(row, index) {
      if (
        null == row.missingNum ||
        row.missingNum == "" ||
        (row.missingNum != "number" && isNaN(row.missingNum))
      ) {
        row.missingNum = 0;
      } else if (row.missingNum <= 0) {
        row.missingNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.missingNum > row.number) {
        row.missingNum = 0;
        this.$message.warning("漏件数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) +
          parseInt(row.missingNum) +
          parseInt(row.damagedNum) >
        row.number
      ) {
        row.missingNum = 0;
        this.$message.warning("正常 + 破损 +漏件 不能大于原单数量");
      }

      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeMissing(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.missingNum >= row.number) {
          this.$message.warning("漏件不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("正常+破损+漏件 不能大于原单数量");
        } else {
          row.missingNum++;
        }
      } else {
        row.missingNum--;
        row.missingNum > 0 ? row.missingNum : (row.missingNum = 0);
      }

      this.$set(this.content.orderCommodityList, index, {
        commodityId: row.commodityId,
        brandName: row.brandName,
        name: row.name,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });

      // console.log(this.content.orderCommodityList);

      this.calculation();
    },
    /**
     * 商品已收 破损 漏件 数量操作修改
     **/

    /**
     * 赠品已收 破损 漏件 数量操作修改
     **/
    changCountRecivedZp(row, index) {
      if (
        null == row.receivedNum ||
        row.receivedNum == "" ||
        (row.receivedNum != "number" && isNaN(row.receivedNum))
      ) {
        row.receivedNum = 0;
      } else if (row.receivedNum <= 0) {
        row.receivedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.receivedNum > row.number) {
        row.receivedNum = 0;
        this.$message.warning("正常数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) +
          parseInt(row.missingNum) +
          parseInt(row.damagedNum) >
        row.number
      ) {
        row.receivedNum = 0;
        this.$message.warning("正常 + 破损 + 漏件 不能大于原单数量");
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeRecivedZp(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.receivedNum >= row.number) {
          this.$message.warning("正常数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("正常+破损+漏件 不能大于原单数量");
        } else {
          row.receivedNum++;
        }
      } else {
        row.receivedNum--;
        row.receivedNum > 0 ? row.receivedNum : (row.receivedNum = 0);
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    // 破损
    changeCountDamageZp(row, index) {
      if (
        null == row.damagedNum ||
        row.damagedNum == "" ||
        (row.damagedNum != "number" && isNaN(row.damagedNum))
      ) {
        row.damagedNum = 0;
      } else if (row.damagedNum <= 0) {
        row.damagedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.damagedNum >= row.number) {
        row.damagedNum = 0;
        this.$message.warning("破损数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) +
          parseInt(row.missingNum) +
          parseInt(row.damagedNum) >
        row.number
      ) {
        row.damagedNum = 0;
        this.$message.warning("正常 + 破损 +漏件 不能大于原单数量");
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeDamageZp(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.damagedNum >= row.number) {
          row.damagedNum = 0;
          this.$message.warning("破损数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("正常+破损+漏件 不能大于原单数量");
        } else {
          row.damagedNum++;
        }
      } else {
        row.damagedNum--;
        row.damagedNum > 0 ? row.damagedNum : (row.damagedNum = 0);
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    // 漏件
    changeCountMissingZp(row, index) {
      if (
        null == row.missingNum ||
        row.missingNum == "" ||
        (row.missingNum != "number" && isNaN(row.missingNum))
      ) {
        row.missingNum = 0;
      } else if (row.missingNum <= 0) {
        row.missingNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.missingNum > row.number) {
        row.missingNum = 0;
        this.$message.warning("正常数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) +
          parseInt(row.missingNum) +
          parseInt(row.damagedNum) >
        row.number
      ) {
        row.missingNum = 0;
        this.$message.warning("正常 + 破损 + 漏件 不能大于原单数量");
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    changeMissingZp(row, type, index) {
      let addNum =
        parseInt(row.receivedNum) +
        parseInt(row.missingNum) +
        parseInt(row.damagedNum);
      if (type > 0) {
        if (row.missingNum >= row.number) {
          this.$message.warning("正常数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("正常+破损+漏件 不能大于原单数量");
        } else {
          row.missingNum++;
        }
      } else {
        row.missingNum--;
        row.missingNum > 0 ? row.missingNum : (row.missingNum = 0);
      }
      this.$set(this.content.orderComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brandName: row.brandName,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
      });
      this.calculation();
    },
    /**
     * 赠品已收 破损 漏件 数量操作修改
     **/
    /**
     * 统计已收，破损，漏件
     **/
    calculation() {
      let receivedTotal = 0;
      let damagedTotal = 0;
      let missingTotal = 0;
      let orginNumber = 0;

      for (let i = 0; i < this.content.orderCommodityList.length; i++) {
        receivedTotal += Number(this.content.orderCommodityList[i].receivedNum);
        damagedTotal += Number(this.content.orderCommodityList[i].damagedNum);
        missingTotal += Number(this.content.orderCommodityList[i].missingNum);
        orginNumber += Number(this.content.orderCommodityList[i].number);
      }

      this.orginNumber = orginNumber;
      this.together = receivedTotal + missingTotal + damagedTotal; //商品总数据量（正常+破损+漏件）

      let receivedTotalZp = 0;
      let damagedTotalZp = 0;
      let missingTotalZp = 0;
      if (!this.is_null(this.content.orderComplimentaryList)) {
        for (let i = 0; i < this.content.orderComplimentaryList.length; i++) {
          receivedTotalZp += Number(
            this.content.orderComplimentaryList[i].receivedNum
          );
          damagedTotalZp += Number(
            this.content.orderComplimentaryList[i].damagedNum
          );
          missingTotalZp += Number(
            this.content.orderComplimentaryList[i].missingNum
          );
        }
      }
      this.receivedTogether = receivedTotal + receivedTotalZp;
      this.damagedTogether = damagedTotal + damagedTotalZp;
      this.missingTogether = missingTotal + missingTotalZp;

      this.backNumTotal =
        this.receivedTogether + this.missingTogether + this.damagedTogether; //商品+赠品
    },
    /**
     * 提交拒收申请
     **/
    submitEvent() {
      let commodityRequests = [];
      for (let i = 0; i < this.content.orderCommodityList.length; i++) {
        // 统计商品信息
        let goods = {
          brokenNo: this.content.orderCommodityList[i].missingNum,
          commodityId: this.content.orderCommodityList[i].commodityId,
          destroyNo: this.content.orderCommodityList[i].damagedNum,
          image: "",
          number: this.content.orderCommodityList[i].number,
          receivedNo: this.content.orderCommodityList[i].receivedNum,
          total: this.content.orderCommodityList[i].total,
          warId: this.content.orderCommodityList[i].warId,
        };
        commodityRequests.push(goods);
      }
      // console.log(commodityRequests);
      let complimentaryRequests = [];
      if (!this.is_null(this.content.orderComplimentaryList)) {
        // 统计赠品信息
        for (let i = 0; i < this.content.orderComplimentaryList.length; i++) {
          let gifts = {
            brokenNo: this.content.orderComplimentaryList[i].missingNum,
            complimentaryId: this.content.orderComplimentaryList[i]
              .complimentaryId,
            destroyNo: this.content.orderComplimentaryList[i].damagedNum,
            image: "",
            number: this.content.orderComplimentaryList[i].number,
            receivedNo: this.content.orderComplimentaryList[i].receivedNum,
            total: this.content.orderComplimentaryList[i].total,
            warId: this.content.orderComplimentaryList[i].warId,
          };
          complimentaryRequests.push(gifts);
        }
      }

      if (this.together > 0 && this.together == this.orginNumber) {
        this.$msgbox({
          title: "确定提交拒收",
          message:
            "总 计 : 已收" +
            this.receivedTogether +
            "件, 破损 : " +
            this.damagedTogether +
            "件, 漏件 : " +
            this.missingTogether +
            " 件",
          showCancelButton: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          beforeClose: (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = "执行中...";
              setTimeout(() => {
                done();
                setTimeout(() => {
                  instance.confirmButtonLoading = false;
                }, 300);
              }, 1000);
            } else {
              done();
            }
          },
        })
          .then((res) => {
            if (this.jage == 0) {
              this.logisticsCompany = this.content.orderUser.logisticsOrder.logisticsCompany;
              this.logistCode = this.content.orderUser.logisticsOrder.parcelNumber;
            }
            this.axios
              .post("/order/order/reject/addrejectorder", {
                brokenTotal: this.missingTogether,
                commodityRequests: commodityRequests,
                complimentaryRequests: complimentaryRequests,
                destroyTotal: this.damagedTogether,
                logisticsCompany: this.logisticsCompany,
                oldId: this.content.orderUser.orderId,
                orderType: this.jage, //订单类型（0:拒收 1:被退货）
                parcelNumber: this.logistCode, //物流单号
                returnMoney: this.content.orderUser.total, //退货金额（总价）
                returnTotal: this.backNumTotal, //商品收到数量（总计) 已收
                shouldReturnMoney: this.content.orderUser.total, //应退货金额 已收
                totalReturnNumber: this.packages, //总退货数
                comment: this.textarea,
              })
              .then((res) => {
                console.log(res);
                if (res.code == 0) {
                  this.$message.success("提交成功");
                  if (this.jage == 0) {
                    this.$router.push({
                      name: "orderList",
                      query: {
                        activeName: "5",
                      },
                    });
                  } else if (this.jage == 1) {
                    this.$router.push({
                      name: "orderList",
                      query: {
                        activeName: "6",
                      },
                    });
                  }
                } else {
                  this.$message.warning(res.message);
                }
              });
          })
          .catch(() => {});
      } else {
        this.$message.error("拒收或被退货总数与原单总数不一致，要求全部退回");
      }
    },
    /**
     * 提交拒收申请
     **/

    is_null(content) {
      if (content) {
        return false;
      } else {
        return true;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.div1 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb2.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}

.div2 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb1.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}

.div3 {
  margin-left: -8px;
  background: url(../../../assets/breadcrumb3.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}

/deep/.el-table td,
.el-table th {
  text-align: center;
}

.container {
  .orderInfo {
    background: #fff;
    padding: 10px 20px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 0px;
    }

    .content {
      .contentTemp {
        .fontTemp {
          margin-top: 10px;
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          padding: 5px 0px;

          p {
            span {
              color: #ff5656;
            }

            font-size: 14px;
            color: #666666;
          }

          > div {
            margin-left: 10px;

            /deep/.el-input__inner {
              height: 30px;
              line-height: 30px;
            }

            /deep/.el-input__icon {
              height: 30px;
              line-height: 30px;
            }
          }

          .span {
            color: #666666;
            font-weight: 400;
            line-height: 20px;
            font-size: 14px;
            margin-right: 40px;
            word-spacing: 8px;
          }

          .span1 {
            display: inline-block;
            width: 50px;
            text-align: justify;
            text-justify: distribute-all-lines;
            /*ie6-8*/
            text-align-last: justify;
            /* ie9*/
            -moz-text-align-last: justify;
            /*ff*/
            -webkit-text-align-last: justify;
            /*chrome 20+*/
          }

          @media screen and (-webkit-min-device-pixel-ratio: 0) {
            /* chrome*/
            .test1:after {
              content: ".";
              display: inline-block;
              width: 100%;
              overflow: hidden;
              height: 0;
            }
          }
        }
      }
    }
  }

  .goodDetail {
    background: #fff;
    padding: 10px 12px;
    margin-top: 10px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 12px;
    }

    .totalAll {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      padding: 10px;
      border-bottom: 1px solid #e3e7ec;

      span {
        margin-left: 30px;
        font-size: 14px;
        font-weight: 550;
      }
    }

    .total {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      padding: 10px;

      span {
        font-size: 14px;
        font-weight: 500;
        color: #5276e9;
        font-weight: 600;
      }
    }
  }

  .remark {
    background: #fff;
    padding: 10px 20px;
    margin-top: 10px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 0px;
      margin-bottom: 10px;
    }
  }

  .submit {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    display: flex;
    justify-content: flex-end;
    padding: 10px 20px;
    z-index: 100;
  }
}

.inputDeal {
  display: flex;
  justify-content: space-around;
  align-items: center;

  span {
    font-size: 13px;
  }
}

.inputDeal:nth-child(2) {
  margin: 8px 0;
}

.numer {
  /deep/.el-button {
    padding: 0;
    margin: 0;
    background: #fff;
    height: 18px;
    line-height: 18px;
    width: 22px;
    text-align: center;
    font-size: 10px;
    color: #333;
    // font-weight: bold;
  }

  /deep/.el-input-group__prepend {
    padding: 0;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
  }

  /deep/ .el-input-group {
    width: 80px;
  }

  /deep/.el-input-group__append {
    padding: 0;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
  }

  /deep/.el-input__inner {
    width: 80px;
    text-align: center;
    padding: 0;
    margin: 0 5px;
    height: 24px;
    line-height: 24px;
    background: #f2f2f2;
    border-radius: 4px;
    border: none;
    color: #666;
    font-size: 10px;
  }
}
</style>
